package com.yuanfeng.biz.front.buy.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yuanfeng.biz.front.buy.service.BookSearchService;
import com.yuanfeng.biz.front.buy.service.BookSearchServiceImpl;
import com.yuanfeng.entity.Books;
import com.yuanfeng.util.BaseServlet;

public class BookSearchServlet extends BaseServlet {

	private BookSearchService bookSearch = new BookSearchServiceImpl();
	public  void query(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//得到书名
		String bookName = request.getParameter("bookName");
		System.out.println(bookName);
		if(bookName != null) {
			Books book = bookSearch.searchBook(bookName);
			if(book == null) {
				//为空查询无此图书
				request.setAttribute("result","failed");
				request.getRequestDispatcher("/jsp/front/shopIndex.jsp").forward(request, response);;
				return;
			}else {
				//查询成功，即将转发
				request.setAttribute("book",book);
				request.getRequestDispatcher("/jsp/front/book/detail.jsp").forward(request, response);
				return;
			}
		}
	}

}
